package com.weiso.weisophonebook.adapter;

import java.util.List;

import com.weiso.weisophonebook.R;
import com.weiso.weisophonebook.bean.LinkMan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LinkManListAdapter extends BaseAdapter {
	Context context;
	List<LinkMan> linkmanlist;
	String str1="";
	String str2="";
	public LinkManListAdapter(Context context,List<LinkMan> linkmanlist){
		this.context=context;
		this.linkmanlist = linkmanlist;
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return linkmanlist.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return linkmanlist.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		LinkmanListItem linkmanitem;
        if(arg1==null){
        	linkmanitem = new LinkmanListItem();
        	arg1 = LayoutInflater.from(context).inflate(R.layout.linkman_list_item, null);
        	linkmanitem.name= (TextView) arg1.findViewById(R.id.linkman_list_item_name);
        	linkmanitem.number= (TextView) arg1.findViewById(R.id.linkman_list_item_number);
        	linkmanitem.alpha=(TextView) arg1.findViewById(R.id.alpha);
        	linkmanitem.headimg=(ImageView) arg1.findViewById(R.id.image_view);
        	arg1.setTag(linkmanitem);
        }else{
        	linkmanitem = (LinkmanListItem) arg1.getTag();
        }
        final LinkMan linkman = linkmanlist.get(arg0);
		
        linkmanitem.name.setText(linkman.getName());
        linkmanitem.number.setText(linkman.getNumber());
        str1=linkman.getHeadchar();
        if(linkman.isAlphashow()){
        	
        	linkmanitem.alpha.setText(linkman.getHeadchar());
        	linkmanitem.alpha.setVisibility(View.VISIBLE);
        }else{
        	linkmanitem.alpha.setVisibility(View.GONE);
        }
        
//      linkmanitem.headimg
        
		return arg1;
	}
    class LinkmanListItem{
    	TextView alpha;
    	TextView name;
    	TextView number;
    	ImageView headimg;
	}
}
